import json
#
import requests
#
#
# """requests常用方法"""
# # requests.request()
# # res = requests.get("http://www.baidu.com")
#
# """response 常用方法"""
# # print(res.headers) # 响应头
# # print(res.request.headers) # 请求头
# # print(res.content) # 响应体，但需手动解码
# # print(res.content.decode(encoding="utf-8")) # 手动解码后的响应体
# # print(res.text) # 自动解码，有概率乱码
# # print(res.raw) # 原始的响应体
# # print(res.status_code) # 响应码
# """接口请求的模拟-登录"""
# # 1.请求参数
# yaml_data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# headers = {
#     "content-type": "application/json"
# }
#
# url = "http://shop-xo.hctestedu.com/index.php?s=api/user/login&application=app&application_client_type=weixin"
# res = requests.post(headers=headers, url=url, json=data)
# print(res.text)
# print(res.status_code)
#
# # 2.公共参数
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# res = requests.post(url=url2, headers=headers, json=data, params=params)
# print(res.status_code)
#
# # 3.模拟404场景
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login1234"
# res = requests.post(url=url2, headers=headers, json=data, params=params)
# print(res.status_code)
#
# # 4.输出响应结果形式展示
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# res = requests.post(url=url2, headers=headers, json=data, params=params)
# print(res.content) # 无解码，纯字节流
# print(res.content.decode(encoding="utf-8")) # 手动解码
# print(res.text) # 输出响应结果，自动解码（概率乱码）
# print(res.json()) # 输出响应结果，将json格式转为字典
# print(res.raw) # 输出响应结果，对象在内存中的地址
#
# # 5.通过响应结果，查看请求信息
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# res = requests.post(url=url2, headers=headers, json=data, params=params)
# print(res.request.url) # 请求地址
# print(res.request.method) # 请求方法
# print(res.request.path_url) # 请求路径
# print(res.request.headers) # 请求头
#
# """json=data 和 data=data 的区别
# json = data : 请求头设置为 content-type： application-json
# data = data : 请求头设置为 content-type： application/x-www-form-urlencoded
# """
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# res = requests.post(url=url2, headers=headers, json=data, params=params)
# print(res.request.headers)
# print(res.headers)
# """================拓展 data = data"""
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# headers = {
#     "content-type": "application/x-www-form-urlencoded"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# res = requests.post(url=url2, headers=headers, data=data, params=params)
# print(res.request.headers)
# print(res.headers)
# print(res.text)
#
# """data=data的转化为json=data"""
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# headers = {
#     "content-type": "application/x-www-form-urlencoded"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# res = requests.post(url=url2, headers=headers, data=json.dumps(data), params=params)
# print(res.request.headers)
# print(res.json())
# # assert "登录成功" == res.json()['msg']
#
# """多接口在一个用例，一个接口调用失败，如何房子程序中止"""
# # 第一个接口
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# headers = {
#     "content-type": "application/x-www-form-urlencoded"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login1234"
# res = requests.post(url=url2, headers=headers, json=data, params=params)
# # print(res.status_code)
# # assert 200 == res.status_code
# # 第二个接口
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# headers = {
#     "content-type": "application/x-www-form-urlencoded"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# # res = requests.post(url=url2, headers=headers, json=data, params=params)
# try:
#     url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login1234"
#     res = requests.post(url=url2, headers=headers, json=data, params=params)
#     assert 200 == res.status_code
# except:
#     pass
#
# """timeout"""
# data = {
#     "accounts": "hu2374145",
#     "pwd": "hu2374145",
#     "type": "username"
# }
# headers = {
#     "content-type": "application/x-www-form-urlencoded"
# }
# params = {
#     "application": "app",
#     "application_client_type": "weixin"
# }
# url2 = "http://shop-xo.hctestedu.com/index.php?s=api/user/login"
# res = requests.post(url=url2, headers=headers, json=data, params=params,timeout=0.01)

















